/*
 * =====================================================================================
 *
 *       Filename:  test.cpp
 *
 *    Description:  Do some test to Queue, test method is compare Queue with std::queue,
 *                  do same operations to Queue and std::queue, and whether the result
 *                  is the same
 *
 *        Version:  1.0
 *        Created:  04/23/2012 06:00:10 PM
 *       Revision:  none
 *       Compiler:  g++
 *
 *         Author:  shangmin.pku (Jesse Shang), shangmin.pku@gmail.com
 *
 * =====================================================================================
 */
#include "Queue.h"

#include <iostream>
#include <queue>

using namespace std;
using namespace algorithm::practice;

void check(Queue<int>& queueToTest, queue<int>& standardQueue) {
  if (!standardQueue.empty()) {
    cout << "queueToTest.front = " << queueToTest.front() << ", standardQueue.front = " << standardQueue.front() << endl;
    cout << "queueToTest.back = " << queueToTest.back() << ", standardQueue.back = " << standardQueue.back() << endl;
  }
  cout << "queueToTest.size = " << queueToTest.size() << ", standardQueue.size = " << standardQueue.size() << endl;
  cout << "queueToTest.empty = " << queueToTest.empty() << ", standardQueue.empty = " << standardQueue.empty() << endl;
  if ((standardQueue.empty() || queueToTest.front() == standardQueue.front() && queueToTest.back() == standardQueue.back()) &&
      queueToTest.size() == standardQueue.size() && queueToTest.empty() == standardQueue.empty()) {
    cout << "---------------------->Check OK" << endl;
  } else {
    cout << "---------------------->Check Error!" << endl;
  }
}

void handlePushCmd(Queue<int>& queueToTest, queue<int>& standardQueue) {
  cout << "Input a int number:" << endl;
  int num;
  cin >> num;
  queueToTest.push(num);
  standardQueue.push(num);
  check(queueToTest, standardQueue); 
}

void handlePopCmd(Queue<int>& queueToTest, queue<int>& standardQueue) {
  queueToTest.pop();
  standardQueue.pop();
  check(queueToTest, standardQueue); 
}

void handleFrontCmd(Queue<int>& queueToTest, queue<int>& standardQueue) {
  cout << "Queue.front = " << queueToTest.front() << ", queue.front = " << standardQueue.front() << endl;
  if (queueToTest.front() == standardQueue.front()) {
    cout << "---------------------->Check OK" << endl;
  } else {
    cout << "---------------------->Check Error!" << endl;
  }
}

void handleBackCmd(Queue<int>& queueToTest, queue<int>& standardQueue) {
  cout << "Queue.back = " << queueToTest.back() << ", queue.back = " << standardQueue.back() << endl;
  if (queueToTest.back() == standardQueue.back()) {
    cout << "---------------------->Check OK" << endl;
  } else {
    cout << "---------------------->Check Error!" << endl;
  }
}

void handleEmptyCmd(const Queue<int>& queueToTest, const queue<int>& standardQueue) {
  cout << "Queue.empty = " << queueToTest.empty() << ", queue.empty = " << standardQueue.empty() << endl;
  if (queueToTest.empty() == standardQueue.empty()) {
    cout << "---------------------->Check OK" << endl;
  } else {
    cout << "---------------------->Check Error!" << endl;
  }
}

void handleSizeCmd(const Queue<int>& queueToTest, const queue<int>& standardQueue) {
  cout << "Queue.size = " << queueToTest.size() << ", queue.size = " << standardQueue.size() << endl;
  if (queueToTest.size() == standardQueue.size()) {
    cout << "---------------------->Check OK" << endl;
  } else {
    cout << "---------------------->Check Error!" << endl;
  }
}

int main(int argc, char* argv[]) {
  Queue<int> queueToTest;
  queue<int> standardQueue;
  while (true) {
    cout << "Do more operation(yes or no)?" << endl;
    string answer;
    cin >> answer;
    if (answer.compare("yes") != 0) {
      break;
    }
    cout << "Input cmd (push, pop, front, back, empty, size):" << endl;
    string cmd;
    cin >> cmd;
    if (cmd.compare("push") == 0) {
      handlePushCmd(queueToTest, standardQueue);
    } else if (cmd.compare("pop") == 0) {
      handlePopCmd(queueToTest, standardQueue);
    } else if (cmd.compare("front") == 0) {
      handleFrontCmd(queueToTest, standardQueue);
    } else if (cmd.compare("back") == 0) {
      handleBackCmd(queueToTest, standardQueue);
    } else if (cmd.compare("empty") == 0) {
      handleEmptyCmd(queueToTest, standardQueue);
    } else if (cmd.compare("size") == 0) {
      handleSizeCmd(queueToTest, standardQueue);
    }
  }
  return 0;
}
